PWD:=$(shell pwd)

OUTPUT_DIR:=$(PWD)/../output
LIB_NAME:=libcjson.a
TEST_EXE:=cjson_test

ifeq ($(HOST),)
CROSS_COMPILE:=
else
CROSS_COMPILE:=$(HOST)-
endif

CC:=$(CROSS_COMPILE)gcc
AR:=$(CROSS_COMPILE)ar

all:
	$(CC) cJSON.c -c -o cJSON.o 
	$(AR) -r $(LIB_NAME) cJSON.o
	
test:
	$(CC) *.c -o $(TEST_EXE) -lm
	
install:
	@mkdir -p $(OUTPUT_DIR)/lib
	@mkdir -p $(OUTPUT_DIR)/bin
	@mkdir -p $(OUTPUT_DIR)/include
	@cp $(LIB_NAME) $(OUTPUT_DIR)/lib
	@cp cJSON.h $(OUTPUT_DIR)/include/
	@cp $(TEST_EXE) $(OUTPUT_DIR)/bin
	
.PHONY: clean
clean:
	@rm -rf *.o *.a $(TEST_EXE)
